package router

import (
	"github.com/gin-gonic/gin"
	"shop-security/preAuthorize"
	"shop-sys/controller"
)

func PrivateSysUser(router *gin.RouterGroup) {
	api := &controller.SysUserController{}
	sysUserRouter := router.Group("/sys/user")
	{
		sysUserRouter.GET("/page", preAuthorize.HasPermission("sys:user:page"), api.Page)             //分页用户列表
		sysUserRouter.GET("/info", api.Info)                                                          //获取登录的用户信息
		sysUserRouter.PUT("/password", preAuthorize.HasPermission("sys:user:update"), api.Password)   //修改密码                                             //修改登录用户密码
		sysUserRouter.GET("/info/:userId", preAuthorize.HasPermission("sys:user:info"), api.GetByUid) //用户信息
		sysUserRouter.PUT("", preAuthorize.HasPermission("sys:user:update"), api.Update)              //修改用户
		sysUserRouter.PUT("/status", preAuthorize.HasPermission("sys:user:update"), api.UpdateStatus) //修改状态
		sysUserRouter.DELETE("/:userId", preAuthorize.HasPermission("sys:user:delete"), api.Delete)   //删除用户
		sysUserRouter.DELETE("/logout", api.Logout)                                                   //退出登陆
	}
}

func PublicSysUser(router *gin.RouterGroup) {
	sysUserRouter := router.Group("/sys/user")
	{
		sysUserRouter.POST("/login/:captchaId/:code", controller.VerifyCaptchaCode(), controller.Login) //用户登陆
		sysUserRouter.POST("", preAuthorize.HasPermission("sys:user:save"), controller.Save)            //创建用户
		sysUserRouter.PUT("/refresh", controller.RefreshToken)                                          //刷新token
	}
}
